package pcjavanet.mobilesell.web.action;

import java.util.List;

import javax.annotation.Resource;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.apache.struts2.convention.annotation.ParentPackage;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import pcjavanet.mobilesell.model.Unit;
import pcjavanet.mobilesell.model.PageBean;
import pcjavanet.mobilesell.model.QryCondition;
import pcjavanet.mobilesell.service.UnitService;

import com.opensymphony.xwork2.ActionSupport;
@Namespace("/unit")
@Controller
@Scope("prototype")
@ParentPackage("json-default")
@Results({
	@Result(name = "success", location = "/view/Unit.jsp"),
	@Result(name = "input", location = "/view/Unit.jsp")
})

public class UnitAction  extends ActionSupport {

  @Resource
  private UnitService unitService;
  private   java.lang.Integer dbid ;
  private   java.lang.String name ;
  private   java.util.Date createDate ;
  private int start  ;
  private int limit  ;
  private int totalProperty  ;
  private boolean success = true ;
  private String  info ;
  private List<Unit>  unitPageBeans  ;
  public    java.lang.Integer getDbid() {
   	return this.dbid;
  }
  public void setDbid(  java.lang.Integer  dbid) {
   	 this.dbid=dbid;
  }
  public    java.lang.String getName() {
   	return this.name;
  }
  public void setName(  java.lang.String  name) {
   	 this.name=name;
  }
  public    java.util.Date getCreateDate() {
   	return this.createDate;
  }
  public void setCreateDate(  java.util.Date  createDate) {
   	 this.createDate=createDate;
  }
  public  void setStart(int start) {
   	 this.start = start;
  }
  public  void setLimit(int limit) {
   	 this.limit = limit;
  }
  public  void setTotalProperty(int totalProperty) {
   	 this.totalProperty = totalProperty;
  }
  public  void setUnitPageBeans(List<Unit> unitPageBeans){
   	 this.unitPageBeans =unitPageBeans  ;
  }
  public  int getStart( ) {
   	 return this.start;
  }
  public  int getLimit( ) {
   	 return this.limit;
  }
  public  int getTotalProperty( ) {
   	 return this.totalProperty;
  }
  public    List<Unit> getUnitPageBeans(){
   	 return this.unitPageBeans   ;
  }
  public  String getInfo( ) {
   	 return this.info;
  }
  public  void setInfo(String info){
   	 this.info = info ;
  }
  public  boolean getSuccess( ) {
   	 return this.success;
  }
  public  void setSuccess(boolean success){
   	 this.success = success ;
  }

  @Action(value="insertUnit",results = {@Result(name = "success", type = "json")})
  public String  insertUnit() throws Exception{
   	success = false ;
   	info = "" ;
  	Unit bean = new Unit();
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	unitService.insert(bean);
   	success = true ;
   	info = "Add Successful" ;
   	return SUCCESS;
  }

  @Action(value="queryUnit",results = {@Result(name = "success", type = "json")})
  public String  queryUnit() throws Exception{
  	Unit bean = new Unit();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	unitService.selectByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="updateUnit",results = {@Result(name = "success", type = "json")})
  public String  updateUnit() throws Exception{
   	success = false ;
   	info = "" ;
  	Unit bean = new Unit();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
  	bean =unitService.selectByPrimaryKey(bean);
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	unitService.updateByPrimaryKeySelective(bean);
   	success = true ;
   	info = "Update Successful" ;
   	return SUCCESS;
  }

  @Action(value="deleteUnit",results = {@Result(name = "success", type = "json")})
  public String  deleteUnit() throws Exception{
  	Unit bean = new Unit();
  	bean.setDbid(this.dbid); 
  	bean.setName(this.name); 
  	bean.setCreateDate(this.createDate); 
	unitService.deleteByPrimaryKey(bean);
   	return SUCCESS;
  }

  @Action(value="listUnit",results = {@Result(name = "success", type = "json")})
  public String  listUnit() throws Exception{
 	QryCondition qry = RequestUtil.getQryCondition(   (javax.servlet.http.HttpServletRequest)com.opensymphony.xwork2.ActionContext.getContext().get(org.apache.struts2.ServletActionContext.HTTP_REQUEST)); 	PageBean pageBean = new PageBean();
	pageBean.setPageSize( limit );
	pageBean.setStartCount( start );
	totalProperty =unitService.getTotalRecords( qry, pageBean );
	unitPageBeans =unitService.getOnePageBeans( qry, pageBean );
   	return SUCCESS;
  }

  @Action("index")
  public String index() throws Exception{
   	return SUCCESS;
  }

}
